import {
  Inject,
  Controller,
  Provide,
  Post,
  Get,
  ALL,
  Body,
  Query,
} from '@midwayjs/decorator';
import { Context } from 'egg';
// import { User } from '../../entity/user';
// import { IUserOptions } from '../../interface';
import { UserService } from '../../../service/user';
import { BaseController } from '../../base';
import { UserDTO } from '../../../dto/user';
@Provide()
@Controller('/admin')
export class UserController extends BaseController {
  @Inject()
  ctx: Context;

  @Inject()
  userService: UserService;

  @Get('/user/page')
  async page(@Query() page: number) {
    return this.successResponse(await this.userService.page('', page));
  }

  @Post('/user/add')
  async add(@Body(ALL) params: UserDTO) {
    return this.successResponse(await this.userService.addUser(params));
  }

  @Post('/user/update')
  async update(@Body(ALL) params: UserDTO) {
    return this.successResponse(await this.userService.updateUser(params));
  }

  @Post('/user/delete')
  async delete(@Body(ALL) params: UserDTO) {
    return this.successResponse(await this.userService.deleteUser(params));
  }
}
